package org.example.hrpc.loadbalance;

import org.example.hrpc.common.utils.CollectionUtils;

import java.util.List;

/**
 * 抽象负载均衡器
 * 模板方法
 */
public abstract  class AbstractLoadBalance<T> implements LoadBalance<T> {


    protected abstract T selectMethod(List<T> services);

    @Override
    public T select(List<T> services) {
        if(CollectionUtils.isEmpty(services)) {
            return null;
        }
        if(services.size() == 1){
            return services.get(0);
        }
        return selectMethod(services);
    }
}
